package com.ag.lzw.action;


import java.util.Set;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.common.BaseAction;
import com.ag.common.EventUtil;
import com.ag.lzw.common.TaskTreeManager;
import com.ag.lzw.vo.TaskTreeVo;

@Scope("prototype")
@Controller("taskTreeAction")
public class TaskTreeAction extends BaseAction {
	private static final long serialVersionUID = 891781047149206372L;

	private static Logger logger = Logger.getLogger(TaskTreeAction.class);
	
	@Resource(name="taskTreeManager")
	private TaskTreeManager taskTree;	
	/**
	 * 根据任务ID，load属于它的子任务树
	 * @return
	 */
	public String loadTaskTree(){
		
		TaskTreeVo ttv = taskTree.getChildrenTaskTree(tid);
		if(ttv!=null){
		
		logger.info("TaskTree head node id is:"+ttv.getNode().getTId());
	
		this.getRequest().setAttribute("tree", ttv);
		
		return "get_taskTree_succ";
		
		}else{
			logger.info("get tasktree false!");
			return null;
		}
	}	
	/**
	 * 根据事件ID，load属于该事件的任务树
	 * @return
	 */
	public String loadTaskTreeofEvent(){
		String eventID = null;
		
		if(this.getSessionAttribute(EventUtil.PROCESSING_EVENT_ID)!=null){
			eventID = getSessionAttribute(EventUtil.PROCESSING_EVENT_ID).toString(); // 获取当前处置事件的ID
			logger.info("Finding Taskree by Event ID:" + eventID);
			Set<TaskTreeVo> ttvs = taskTree.getTaskTree(eventID);

			if(ttvs!=null&&ttvs.size()!=0){
				logger.info("Loading tree on jsp");
				//logger.info("TaskTree head node id is:"+ttv.getNode().getTId());
				this.getRequest().setAttribute("EId", eventID);
				this.getRequest().setAttribute("tasktree", ttvs);
				
				return "get_eventTaskTree_succ";
			} else {
				logger.info("get eventTaskTree false!");
				this.getRequest().setAttribute("EId", eventID);
				this.getRequest().setAttribute("tasktree", null);
				return "get_eventTaskTree_succ";
			}
		} else {
			logger.info("get eventTaskTree false!because of can not get the event id");
			return "get_eventTaskTree_false";
		}
		
		/*
		logger.info("Finding Taskree by Event ID:" + eid);
		Set<TaskTreeVo> ttvs = taskTree.getTaskTree(eid);
		logger.info(""+ttvs.size());
		
		if(ttvs.size()!=0&&ttvs!=null){
			
			//logger.info("TaskTree head node id is:"+ttv.getNode().getTId());
			
			this.getRequest().setAttribute("tasktree", ttvs);
			
			return "get_eventTaskTree_succ";
		} else {
			logger.info("get eventTaskTree false!");
			return null;
		}
		*/
	}
	

	private String eid;
	
	
	public String getEid() {
		return eid;
	}

	public void setEid(String eid) {
		this.eid = eid;
	}


	private String tid;

	public String getTid() {
		return tid;
	}


	public void setTid(String tid) {
		this.tid = tid;
	}
	
}
